/*
 * @Description:
 * @Author: Wang Su
 * @Date: 2023-09-21 14:40:17
 * @LastEditors: Wang Su
 * @LastEditTime: 2023-10-09 14:20:59
 */
const chartsData = require("../db/bubble_charts_data.json");
const {
  bubble,
  annular,
  radar,
  annularOther,
  deviceAccess,
  deviceStatus,
  versionDistribution,
  onlineRateTrend
} = chartsData;
//气泡图
const bubbleChartsQuery = async (ctx) => {
  let { times } = ctx.request.body;
  try {
    const data = bubble.find((item) => item.times === times) || [];
    if (!data) {
      ctx.throw(404, "No devices found");
    }
    ctx.body = {
      code: 200,
      msg: "查询成功",
      data,
    };
  } catch (err) {
    console.log(err);
    ctx.throw(500, err);
  }
};

//环形图
const annularChartsQuery = async (ctx) => {
  let { times } = ctx.request.body;
  try {
    const data = annular.find((item) => item.times === times) || [];
    if (!data) {
      ctx.throw(404, "No devices found");
    }
    ctx.body = {
      code: 200,
      msg: "查询成功",
      data,
    };
  } catch (err) {
    console.log(err);
    ctx.throw(500, err);
  }
};

//雷达图
const radarChartsQuery = async (ctx) => {
  let { times } = ctx.request.body;
  try {
    const data = radar.find((item) => item.times === times) || [];
    if (!data) {
      ctx.throw(404, "No devices found");
    }
    ctx.body = {
      code: 200,
      msg: "查询成功",
      data,
    };
  } catch (err) {
    console.log(err);
    ctx.throw(500, err);
  }
};
//运维支撑查询
const operateSupportQuery = async (ctx) => {
  let { times } = ctx.request.body;
  try {
    const data = annularOther.find((item) => item.times === times) || [];
    if (!data) {
      ctx.throw(404, "No devices found");
    }
    ctx.body = {
      code: 200,
      msg: "查询成功",
      data,
    };
  } catch (err) {
    console.log(err);
    ctx.throw(500, err);
  }
};

const deviceAccessQuery = async (ctx) => {
  let { times } = ctx.request.body;
  try {
    const data = deviceAccess.find((item) => item.times === times) || [];
    if (!data) {
      ctx.throw(404, "No devices found");
    }
    ctx.body = {
      code: 200,
      msg: "查询成功",
      data,
    };
  } catch (err) {
    ctx.throw(500, err);
  }
};

const deviceTotalQuery = async (ctx) => {
  let { times } = ctx.request.body;
  try {
    const data = deviceStatus.find((item) => item.times === times) || [];
    if (!data) {
      ctx.throw(404, "No devices found");
    }
    ctx.body = {
      code: 200,
      msg: "查询成功",
      data,
    };
  } catch (err) {
    ctx.throw(500, err);
  }
};

const versionDistQuery = async (ctx) => {
  let { times } = ctx.request.body;
  try {
    const data = versionDistribution.find((item) => item.times === times) || [];
    if (!data) {
      ctx.throw(404, "No devices found");
    }
    ctx.body = {
      code: 200,
      msg: "查询成功",
      data,
    };
  } catch (err) {
    ctx.throw(500, err);
  }
};

const onlineRateQuery=async (ctx) => {
  let { times } = ctx.request.body;
  try {
    const data = onlineRateTrend.find((item) => item.times === times) || [];
    if (!data) {
      ctx.throw(404, "No devices found");
    }
    ctx.body = {
      code: 200,
      msg: "查询成功",
      data,
    };
  } catch (err) {
    ctx.throw(500, err);
  }
};
module.exports = {
  bubbleChartsQuery,
  annularChartsQuery,
  radarChartsQuery,
  operateSupportQuery,
  deviceAccessQuery,
  deviceTotalQuery,
  versionDistQuery,
  onlineRateQuery
};
